import Vue from 'vue'
import App from './App.vue'
//导入element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//导入路由包
import Router from "vue-router";
//导入自定义路由
import router from './router'
//导入axios
import axios from   'axios'
//导入store
import store from '@/store/index'
//导入timeLine
import vuetimeline from "@growthbunker/vuetimeline"
//导入公共组件
import sideBar from "@/components/Search/sideBar";
import NavMenu from "@/components/NavMenu";
import '@/assets/font_2848324_re9t5ds1syd/iconfont'
import '@/assets/font_2848324_re9t5ds1syd/iconfont.css'
Vue.config.productionTip = false

Vue.use(ElementUI)
Vue.use(Router)
Vue.use(vuetimeline)
//使用公共组件
Vue.use(sideBar)
Vue.use(NavMenu)

Vue.component('sideBar',sideBar)
axios.defaults.baseURL="http://localhost:8080"
axios.defaults.withCredentials = true;
Vue.prototype.$axios=axios
new Vue({
  render: h => h(App),
  store,
  router,
    //创建的时候就请求到所有信息
    created:initBlog,
  sideBar,
    NavMenu
}).$mount('#app')
//请求博客信息
function initBlog(){
    store.dispatch('getBlogInfo');
}
//让所有的请求头中都包含token参数
axios.interceptors.request.use(
    config=>{
      if(window.sessionStorage.getItem('token')){
        config.headers.token=window.sessionStorage.getItem('token');
      }
      return config;
    },
    error => {
      return Promise.reject(error);
    }
)

